from util import text_generator
import os


def execute():
    if not os.path.exists('image'):
        print(f"目录 'image' 不存在")
        return
    current_directory = os.getcwd()
    for filename in os.listdir('image'):
        if os.path.isfile(os.path.join('image', filename)):
            image_path = os.path.abspath(os.path.join('image', filename))
            file_path = os.path.join(current_directory, filename.split('.')[0] + "_img.txt")
            text = text_generator.getText(image_path)
            with open(file_path, "w", encoding="utf-8") as file:
                file.write(text)


if __name__ == '__main__':
    execute()
